//
//  VolatileSetter.m
//  Staff
//
//  Created by caiyao on 1/14/15.
//
//

#import "VolatileSetter.h"
#import "ShareData.h"

@implementation VolatileSetter

- (void)excute {
    
    NSString *key = [self.command.functionParamsDic objectForKey:@"key"];
    
    if (key == nil || self.command.dataJS == nil)
    {
        // params is missing fail to handle
        [self excuteNonHookFoundCallback];
        return;
    }
    
    NSString *datajsCall = [NSString stringWithFormat:@"%@();",self.command.dataJS];
    NSString *value = [self.webView stringByEvaluatingJavaScriptFromString:datajsCall];
    DebugLog(@"volatile setter pair:%@=%@",key, value);
    
    if (value == nil)
    {
        // value is null fail to handle
        [self excuteNonHookFoundCallback];
        return;
    }
    else
    {
        // save value
        [[ShareData shareInstance] vSetter:key value:value];
    }
    
    [self excuteCallBackJSWithParameters:nil];
}

@end
